package com.cabal.common.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * spring Context容器工具类
 *
 * @author shenkang
 * @date 2022年11月24日
 */
@Component
public class ContextUtil implements ApplicationContextAware {
	
    private static ApplicationContext context;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext)
            throws BeansException {
//        log.info("------ContextUtil setApplicationContext-------");
        context = applicationContext;
    }

    public static ApplicationContext getContext(){
    	
        return context;
    }

    public static Object getBean(String beanName) {
        return context.getBean(beanName);
    }
    
    public static String getEnvProperty(String key){
    	return context.getEnvironment().getProperty(key);
    }
}
